home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWHashTable - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/hashtab.h> RWHashTable h ; DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class is a simple hash table for objects inheriting from RRRRWWWWCCCCoooolllllllleeeeccccttttaaaabbbblllleeee. It uses chaining (as implemented by class RRRRWWWWSSSSlllliiiissssttttCCCCoooolllllllleeeeccccttttaaaabbbblllleeeessss) to resolve hash collisions. Duplicate objects are allowed. An object stored by RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee must inherit from the abstract base class RRRRWWWWCCCCoooolllllllleeeeccccttttaaaabbbblllleeee, with suitable definition for virtual functions hhhhaaaasssshhhh(((()))) and iiiissssEEEEqqqquuuuaaaallll(((()))) (see class RRRRWWWWCCCCoooolllllllleeeeccccttttaaaabbbblllleeee). To find an object that matches a key, the key's virtual function hhhhaaaasssshhhh(((()))) is first called to determine in which bucket the object occurs. The bucket is then searched linearly by calling the virtual function iiiissssEEEEqqqquuuuaaaallll(((()))) for each candidate, with the key as the argument. The first object to return TTTTRRRRUUUUEEEE is the returned object. The initial number of buckets in the table is set by the constructor. There is a default value. If the number of items in the collection greatly exceeds the number of buckets then efficiency will sag because each bucket must be searched linearly. The number of buckets can be changed by calling member function rrrreeeessssiiiizzzzeeee(((()))).... This will require that all objects be rehashed. The iterator for this class is RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeeeIIIItttteeeerrrraaaattttoooorrrr. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee None EEEExxxxaaaammmmpppplllleeee #include <rw/hashtab.h> #include <rw/colldate.h> #include <rw/rstream.h> main(){ RWHashTable table; RWCollectableDate *july = new RWCollectableDate(7, "July", 1990); RWCollectableDate *may = new RWCollectableDate (1, "May", 1977); RWCollectableDate *feb = new RWCollectableDate (22, "Feb", 1983); RWCollectableDate *aug = new RWCollectableDate (2, "Aug", 1966); table.insert(july); table.insert(may); table.insert(feb); PPPPaaaaggggeeee 1111 RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) table.insert(aug); cout << "Table contains " << table.entries() << " entries.0; RWCollectableDate key(22, "Feb", 1983); cout << "It does "; if (!table.contains(&key)) cout << "not "; cout << "contain the key " << key << endl; delete july; delete may; delete feb; delete aug; return 0; } PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt:::: Table contains 4 entries. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss It does contain the key February 22, 1983 RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee(size_t N = RWCollection::DEFAULT_CAPACITY); Construct an empty hash table with NNNN buckets. RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee(const RWHashTable& t); Copy constructor. Create a new hash table as a shallow copy of the table tttt. The new table will have the same number of buckets as the old table. Hence, the members need not be and will not be rehashed. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss void ooooppppeeeerrrraaaattttoooorrrr====(const RWHashTable& t); Assignment operator. Sets self as a shallow copy of tttt. Afterwards, the two tables will have the same number of buckets. Hence, the members need not be and will not be rehashed. RWBoolean ooooppppeeeerrrraaaattttoooorrrr========(const RWHashTable& t) const; Returns TTTTRRRRUUUUEEEE if self and tttt have the same number of elements and if for every key in self there is a corresponding key in tttt which iiiissssEEEEqqqquuuuaaaallll. PPPPaaaaggggeeee 2222 RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) RWBoolean ooooppppeeeerrrraaaattttoooorrrr<<<<====(const RWHashTable& t) const; Returns TTTTRRRRUUUUEEEE if self is a subset of tttt, that is, every element of self has a counterpart in tttt which iiiissssEEEEqqqquuuuaaaallll. NNNNooootttteeee: If you inherit from RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee in the presence of the Standard C++ Library, we recommend that you override this operator and explicitly forward the call. Overload resolution in C++ will choose the Standard Library provided global operators over inherited class members. These global definitions are not appropriate for set-like partial orderings. RWBoolean ooooppppeeeerrrraaaattttoooorrrr!!!!====(const RWHashTable&) const; Returns the negation of ooooppppeeeerrrraaaattttoooorrrr========(((()))), above. MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss virtual void aaaappppppppllllyyyy(RWapplyCollectable ap, void*); Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. The function pointed to by aaaapppp will be called for each member in the collection. Because of the nature of hashing collections, this will not be done in any particular order. The function should not do anything that could change the hash value or equality properties of the objects. virtual RWspace bbbbiiiinnnnaaaarrrryyyySSSSttttoooorrrreeeeSSSSiiiizzzzeeee() const; Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual void cccclllleeeeaaaarrrr(); Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual int ccccoooommmmppppaaaarrrreeeeTTTToooo(const RWCollectable*) const; Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. PPPPaaaaggggeeee 3333 RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) virtual RWBoolean ccccoooonnnnttttaaaaiiiinnnnssss(const RWCollectable*) const; Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual size_t eeeennnnttttrrrriiiieeeessss() const; Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual RWCollectable* ffffiiiinnnndddd(const RWCollectable*) const; Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual unsigned hhhhaaaasssshhhh() const; Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual RWCollectable* iiiinnnnsssseeeerrrrtttt(RWCollectable* a); Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. Returns aaaa if successful, nnnniiiillll otherwise. virtual RWClassID iiiissssAAAA() const; Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn to return ________RRRRWWWWHHHHAAAASSSSHHHHTTTTAAAABBBBLLLLEEEE. virtual RWBoolean iiiissssEEEEmmmmppppttttyyyy() const; Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual RWBoolean iiiissssEEEEqqqquuuuaaaallll(const RWCollectable*) const; Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual RWCollectable* nnnneeeewwwwSSSSppppeeeecccciiiieeeessss() const; PPPPaaaaggggeeee 4444 RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) RRRRWWWWHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++)))) Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual size_t ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const RWCollectable*) const; Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual RWCollectable* rrrreeeemmmmoooovvvveeee(const RWCollectable*); Redefined from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual void rrrreeeemmmmoooovvvveeeeAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(const RWCollectable*); Inherited from RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. virtual void rrrreeeessssiiiizzzzeeee(size_t n = 0); Resizes the internal hash table to have nnnn buckets. This causes rehashing all the members of the collection. If nnnn is zero, then an appropriate size will be picked automatically. virtual void rrrreeeessssttttoooorrrreeeeGGGGuuuuttttssss(RWvistream&); virtual void rrrreeeessssttttoooorrrreeeeGGGGuuuuttttssss(RWFile&); virtual void ssssaaaavvvveeeeGGGGuuuuttttssss(RWvostream&) const; virtual void ssssaaaavvvveeeeGGGGuuuuttttssss(RWFile&) const; Inherited from class RRRRWWWWCCCCoooolllllllleeeeccccttttiiiioooonnnn. RWStringID ssssttttrrrriiiinnnnggggIIIIDDDD(); (acts virtual) Inherited from class RRRRWWWWCCCCoooolllllllleeeeccccttttaaaabbbblllleeee. PPPPaaaaggggeeee 5555